package days2.Scanner;

import org.junit.Test;

import java.util.Scanner;

/**
 * @Author fengzihao
 * @Date 2024-04-16 20:18
 */
public class Practice {
    // Scanner
    @Test
    public void test1() {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        System.out.println("num = " + num);
    }

    //    多种类型输入,要用nextLine()，然后在进行转换
//    原因是终止信号不一样！！！！！！！！！！！！！
    @Test
    public void test2() {
        Scanner scanner = new Scanner(System.in);
//        输入一个整数
        String s1 = scanner.nextLine();
        int intnum = Integer.parseInt(s1);
        System.out.println("intnum = " + intnum);
//        输入一个浮点数
        String s2 = scanner.nextLine();
        double doublenum = Double.parseDouble(s2);
        System.out.println("doublenum = " + doublenum);
//        输入一个字符串
        String s3 = scanner.nextLine();
        System.out.println("s3 = " + s3);
    }

    //  小测验-用户名密码验证
    @Test
    public void test3() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userName = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        if ("admin".equals(userName) && "123456".equals(password))
            System.out.println("登陆成功");
        else
            System.out.println("登陆失败");
    }
}
